﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;

namespace Fengsoft.AIBlog.Web
{
    public class MvcApplication : System.Web.HttpApplication
    {
        private void ConvertToSecuredUrl()
        {
            if (Request.Url.Scheme.Equals(Uri.UriSchemeHttp,StringComparison.OrdinalIgnoreCase))
            {
                string newUrl=string.Empty;
                if (Request.IsLocal)
                {
                    newUrl=string.Format("{0}://localhost:44303{1}",Uri.UriSchemeHttps,Request.Url.PathAndQuery);
                }
                else
                {
                    newUrl=Request.Url.ToString().Replace(Uri.UriSchemeHttp,Uri.UriSchemeHttps);
                }
                Response.Redirect(newUrl);
            }
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
        protected void Application_BeginRequest()
        {
            //ConvertToSecuredUrl();
        }
    }
}
